package cj.web.prize.dao;

/*
 *  
 *  
 */
import java.util.List;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;
import cj.web.prize.domain.PrizeResult;

/**
 * 
 * @author
 *
 */
@DAO
public interface PrizeResultDAO {

	@SQL("select * from PrizeResult where ID=:1 ")
	PrizeResult queryById(String id);

	@SQL("select * from PrizeResult where DeviceID=:1 and ActiveID=:2 ")
	List<PrizeResult> queryByDeviceID(String DeviceID, String ActiveID);

	@SQL("select * from PrizeResult where ActiveID=:1 and Status<>:2 ")
	List<PrizeResult> queryByActiveID(int ActiveID, int Status);

	@SQL("select * from PrizeResult where ActiveID=:1 and Phone=:2 ")
	List<PrizeResult> queryByPhone(String ActiveID, String Phone);

	@SQL("INSERT INTO PrizeResult (ActiveID,Phone,DeviceID,DeviceType,CreateAT,Status,Remark) VALUES ("
			+ ":t.activeId,:t.phone,:t.deviceId,:t.deviceType,now(),:t.status,:t.remark) ")
	void create(@SQLParam("t") PrizeResult PrizeResult);

	@SQL("UPDATE PrizeResult SET ActiveID=:t.activeId,"
			+ "Phone=:t.phone,DeviceID=:t.deviceId,"
			+ "DeviceType=:t.deviceType,CreateAT=:t.createAt,"
			+ "Status=:t.status,Remark=:t.remark WHERE ID=:t.id ")
	void update(@SQLParam("t") PrizeResult PrizeResult);

	@SQL(" select activeId, phone,deviceId, date_format(createAt,'%Y-%m-%d %H:%i:%s') as createAt,status,remark "
			+ "from PrizeResult where activeId=:3 order by ID desc limit :1 ,:2 ")
	List<PrizeResult> queryRSLimit(int begin, int len, String aid);

	@SQL("SELECT count(*) from PrizeResult where ActiveID=:1 ")
	int queryRSTotal(String aid);

	@SQL("UPDATE PrizeResult SET Status=:3 WHERE Phone=:2 and DeviceID=:1 and ActiveID=:4 ")
	void updateState(String DeviceID, String Phone, int Status, String aid);

	@SQL("UPDATE PrizeResult SET Status=:2 WHERE ID=:1 ")
	void updateStateByID(int id, int Status);

	@SQL("UPDATE PrizeGift SET count = count+1 WHERE name=:1 and active_id=:2 ")
	void updateCount(String name, String active);

	@SQL(" SELECT activeId,phone,deviceId,date_format(CreateAT,'%Y-%m-%d %H:%i:%s') as createAt,status,remark "
			+ "FROM PrizeResult WHERE ActiveID=:t.activeId "
			+ "AND (DeviceID  LIKE '%##(:t.remark)%' OR Phone LIKE '%##(:t.remark)%') ORDER BY id DESC LIMIT :t.start ,:t.length ")
	List<PrizeResult> queryBypd(@SQLParam("t")PrizeResult prizeResult);

	@SQL("SELECT COUNT(*) FROM PrizeResult WHERE DeviceID LIKE '%##(:t.remark)%' OR Phone LIKE '%##(:t.remark)%' AND ActiveID=:t.activeId ")
	int queryRSTotalBypd(@SQLParam("t")PrizeResult prizeResult);

}